<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>上传题库</title>
<link rel="stylesheet" type="text/css" href="<%=path %>/style/easyui.css">
<link rel="stylesheet" type="text/css" href="<%=path %>/style/icon.css">
<script type="text/javascript" src="<%=path %>/script/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="<%=path %>/script/jquery.easyui.min.js"></script>
<script type="text/javascript" src="<%=path %>/script/easyui-lang-zh_CN.js"></script>
</head>
<body>
	<div class="easyui-tabs" style="width:700px;height:300px">
		<div title="上传机经题库数据" style="padding:10px">
			
			<form id="kyfm" method="post" enctype="multipart/form-data">
			<div style="margin-bottom:20px">
	            <div>口语题文件:</div>
	            <input id="file_name1" class="easyui-filebox" name="excelData" data-options="prompt:'请选择文件'" style="width:50%">
	            
	        </div>
	        <div>
	            <a href="javascript:void(0)" class="easyui-linkbutton" onclick="uploadKyData()" style="width:50%">上传</a>
	        </div>
	        </form>
		</div>
		
		<div title="上传TPO题库数据" style="padding:10px">
			
			<form id="tpofm" method="post" enctype="multipart/form-data">
			<div style="margin-bottom:20px">
	            <div>TPO文件:</div>
	            <input id="file_name5" class="easyui-filebox" name="excelData" data-options="prompt:'请选择文件'" style="width:50%">
	            
	        </div>
	        <div>
	            <a href="javascript:void(0)" class="easyui-linkbutton" onclick="uploadTpoData()" style="width:50%">上传</a>
	        </div>
	        </form>
		</div>
		
		<div title="上传黄金口语题库数据" style="padding:10px">
			
			<form id="classicfm" method="post" enctype="multipart/form-data">
			<div style="margin-bottom:20px">
	            <div>黄金口语:</div>
	            <input id="file_name7" class="easyui-filebox" name="excelData" data-options="prompt:'请选择文件'" style="width:50%">
	            
	        </div>
	        <div>
	            <a href="javascript:void(0)" class="easyui-linkbutton" onclick="uploadClassicData()" style="width:50%">上传</a>
	        </div>
	        </form>
		</div>


		<div title="上传机经课程数据" style="padding:10px">

			<form id="jjcoursefm" method="post" enctype="multipart/form-data">
				<div style="margin-bottom:20px">
					<div>机经课程:</div>
					<input id="file_name_jjcourse" class="easyui-filebox" name="excelData" data-options="prompt:'请选择文件'" style="width:50%">

				</div>
				<div>
					<a href="javascript:void(0)" class="easyui-linkbutton" onclick="uploadJjCourseData()" style="width:50%">上传</a>
				</div>
			</form>
		</div>
		<!-- 
		<div title="上传写作题库数据" style="padding:10px">
			<form id="xzfm" method="post" enctype="multipart/form-data">
			<div style="margin-bottom:20px">
	            <div>写作题文件:</div>
	            <input id="file_name3" class="easyui-filebox" name="excelData" data-options="prompt:'请选择文件'" style="width:50%">
	            
	        </div>
	        <div>
	            <a href="javascript:void(0)" class="easyui-linkbutton" onclick="uploadXZData()" style="width:50%">上传</a>
	        </div>
	        </form>
		</div>
		
		<div title="上传对应时间" style="padding:10px">
			<form id="kytimefm" method="post" enctype="multipart/form-data">
			<div style="margin-bottom:20px">
	            <div>对应时间表文件:</div>
	            <input id="file_name2" class="easyui-filebox" name="excelData" data-options="prompt:'请选择文件'" style="width:50%">
	            
	        </div>
	        <div>
	            <a href="javascript:void(0)" class="easyui-linkbutton" onclick="uploadKytimeData()" style="width:50%">上传</a>
	        </div>
	        </form>
		</div>
		 
		<div title="上传预测" style="padding:10px">
			<form id="forecastfm" method="post" enctype="multipart/form-data">
			<div style="margin-bottom:20px">
	            <div>对应预测文件:</div>
	            <input id="file_forecast" class="easyui-filebox" name="excelData" data-options="prompt:'请选择文件'" style="width:50%">
	            
	        </div>
	        <div>
	            <a href="javascript:void(0)" class="easyui-linkbutton" onclick="uploadForecastData()" style="width:50%">上传</a>
	        </div>
	        </form>
		</div>
		-->
	</div>
</body>
<script type="text/javascript">
	function uploadKyData(){
		var fileVal = $("#file_name1").textbox("getValue"); 
	       var fileValArr = fileVal.split(".");
	       fileValArr = fileValArr[fileValArr.length-1];
	       if(fileValArr!= 'xls' && fileValArr!= 'xlsx' ) {  
	    	   $.messager.alert('提示','请上传excel文件');
	        return false;  
	       }
	       if(fileVal==''){
	    	   $.messager.alert('提示','请添加文件');
	    	   return false;  
	       }
		$('#kyfm').form('submit', {
			url: '<%=basePath%>test/experience/import?fileType='+fileValArr,
			onSubmit: function(){
				var isValid = $(this).form('validate');
				$.messager.progress({
	                title:'请稍等',
	                msg:'正在上传...',
	                text:'拼命上传中',
	                interval:500
	            });
	            
				if (!isValid){
					$.messager.progress('close');	// hide progress bar while the form is invalid
				}
				return isValid;	// return false will stop the form submission
			},
			success: function(json){
				$.messager.progress('close');	// hide progress bar while submit successfully
				$('#file_name1').textbox("clear");
				var json = eval('('+json+')') ;
				showResult(json) ;
			}
		});
	}
	
	function uploadTpoData(){
		var fileVal = $("#file_name5").textbox("getValue"); 
	       var fileValArr = fileVal.split(".");
	       fileValArr = fileValArr[fileValArr.length-1];
	       if(fileValArr!= 'xls' && fileValArr!= 'xlsx' ) {  
	    	   $.messager.alert('提示','请上传excel文件');
	        return false;  
	       }
	       if(fileVal==''){
	    	   $.messager.alert('提示','请添加文件');
	    	   return false;  
	       }
		$('#tpofm').form('submit', {
			url: '<%=basePath%>test/tpo/import?fileType='+fileValArr,
			onSubmit: function(){
				var isValid = $(this).form('validate');
				$.messager.progress({
	                title:'请稍等',
	                msg:'正在上传...',
	                text:'拼命上传中',
	                interval:500
	            });
	            
				if (!isValid){
					$.messager.progress('close');	// hide progress bar while the form is invalid
				}
				return isValid;	// return false will stop the form submission
			},
			success: function(json){
				$.messager.progress('close');	// hide progress bar while submit successfully
				$('#file_name1').textbox("clear");
				var json = eval('('+json+')') ;
				showResult(json) ;
			}
		});
	}
	
	function uploadClassicData(){
		var fileVal = $("#file_name7").textbox("getValue"); 
	       var fileValArr = fileVal.split(".");
	       fileValArr = fileValArr[fileValArr.length-1];
	       if(fileValArr!= 'xls' && fileValArr!= 'xlsx' ) {  
	    	   $.messager.alert('提示','请上传excel文件');
	        return false;  
	       }
	       if(fileVal==''){
	    	   $.messager.alert('提示','请添加文件');
	    	   return false;  
	       }
		$('#classicfm').form('submit', {
			url: '<%=basePath%>test/classic/import?fileType='+fileValArr,
			onSubmit: function(){
				var isValid = $(this).form('validate');
				$.messager.progress({
	                title:'请稍等',
	                msg:'正在上传...',
	                text:'拼命上传中',
	                interval:500
	            });
	            
				if (!isValid){
					$.messager.progress('close');	// hide progress bar while the form is invalid
				}
				return isValid;	// return false will stop the form submission
			},
			success: function(json){
				$.messager.progress('close');	// hide progress bar while submit successfully
				$('#file_name1').textbox("clear");
				var json = eval('('+json+')') ;
				showResult(json) ;
			}
		});
	}
	
	function uploadKytimeData(){
		var fileVal = $("#file_name2").textbox("getValue"); 
	       var fileValArr = fileVal.split(".");
	       fileValArr = fileValArr[fileValArr.length-1];
	       if(fileValArr!= 'xls' && fileValArr!= 'xlsx') {  
	    	   $.messager.alert('提示','请上传excel文件');
	        return false;  
	       }
		$('#kytimefm').form('submit', {
			url: '<%=basePath%>question/uploadkyTime?file_type='+fileValArr,
			onSubmit: function(){
				var isValid = $(this).form('validate');
				$.messager.progress({
	                title:'请稍等',
	                msg:'正在上传...',
	                text:'拼命上传中',
	                interval:500
	            });
				if (!isValid){
					$.messager.progress('close');	// hide progress bar while the form is invalid
				}
				return isValid;	// return false will stop the form submission
			},
			success: function(json){
				$.messager.progress('close');	// hide progress bar while submit successfully
				$('#file_name2').textbox("clear");
				var json = eval('('+json+')') ;
				showResult(json) ;
			}
		});
	}
	
	function uploadXZData(){
		var fileVal = $("#file_name3").textbox("getValue"); 
	       var fileValArr = fileVal.split(".");
	       fileValArr = fileValArr[fileValArr.length-1];
	       if(fileValArr!= 'xls' && fileValArr!= 'xlsx') {  
	    	   $.messager.alert('提示','请上传excel文件');
	        return false;  
	       }
	       if(fileVal==''){
	    	   $.messager.alert('提示','请添加文件');
	    	   return false;  
	       }
		$('#xzfm').form('submit', {
			url: '<%=basePath%>question/uploadXzData?file_type='+fileValArr,
			onSubmit: function(){
				var isValid = $(this).form('validate');
				$.messager.progress({
	                title:'请稍等',
	                msg:'正在上传...',
	                text:'拼命上传中',
	                interval:500
	            });
				if (!isValid){
					$.messager.progress('close');	// hide progress bar while the form is invalid
				}
				return isValid;	// return false will stop the form submission
			},
			success: function(json){
				$.messager.progress('close');	// hide progress bar while submit successfully
				$('#file_name3').textbox("clear");
				var json = eval('('+json+')') ;
				showResult(json) ;
			}
		});
	}
	//上传预测
	function uploadForecastData(){
		var fileVal = $("#file_forecast").textbox("getValue"); 
	       var fileValArr = fileVal.split(".");
	       fileValArr = fileValArr[fileValArr.length-1];
	       if(fileValArr!= 'xls' && fileValArr!= 'xlsx') {  
	    	   $.messager.alert('提示','请上传excel文件');
	        return false;  
	       }
		$('#forecastfm').form('submit', {
			url: '<%=basePath%>forecast/uploadForecast?file_type='+fileValArr,
			onSubmit: function(){
				var isValid = $(this).form('validate');
				$.messager.progress({
	                title:'请稍等',
	                msg:'正在上传...',
	                text:'拼命上传中',
	                interval:500
	            });
				if (!isValid){
					$.messager.progress('close');	// hide progress bar while the form is invalid
				}
				return isValid;	// return false will stop the form submission
			},
			success: function(json){
				$.messager.progress('close');	// hide progress bar while submit successfully
				$('#file_name2').textbox("clear");
				var json = eval('('+json+')') ;
				showResult(json) ;
			}
		});
	}

	//上传机经课程数据
	function uploadJjCourseData(){
		var fileVal = $("#file_name_jjcourse").textbox("getValue");
		var fileValArr = fileVal.split(".");
		fileValArr = fileValArr[fileValArr.length-1];
		if(fileValArr!= 'xls' && fileValArr!= 'xlsx') {
			$.messager.alert('提示','请上传excel文件');
			return false;
		}
		$('#jjcoursefm').form('submit', {
			url: '<%=basePath%>test/qu_course/import?fileType='+fileValArr,
			onSubmit: function(){
				var isValid = $(this).form('validate');
				$.messager.progress({
					title:'请稍等',
					msg:'正在上传...',
					text:'拼命上传中',
					interval:500
				});
				if (!isValid){
					$.messager.progress('close');	// hide progress bar while the form is invalid
				}
				return isValid;	// return false will stop the form submission
			},
			success: function(json){
				$.messager.progress('close');	// hide progress bar while submit successfully
				$('#file_name_jjcourse').textbox("clear");
				var json = eval('('+json+')') ;
				showResult(json) ;
			}
		});
	}
	
	function showResult(json){
		
		var result = json.result ;
		var errdatacount = parseInt(json.errdatacount) ;
		var errmsg = json.msg ;
		if(result==1){
			
			$.messager.alert('提示','上传成功'+(errdatacount>0?',有'+errdatacount+'条数据格式不对':''));
		}else if(result==2){
			$.messager.alert('提示','excel文件解析错误（题号不存在）'+(errdatacount>0?',有'+errdatacount+'条数据格式不对':''));
		}else{
			if(errmsg){
				$.messager.alert('提示',errmsg);
			}else{
				$.messager.alert('提示','上传失败，服务器内部出错');
			}
		}
	}
	
</script>
</html>